<template>
  <div class="wise-view">
    <el-form label-width="100px" class="show-form" label-suffix=":">
      <template v-for="(item,index) in columns">
        <el-form-item
          :key="index"
          :label="item.label"
          :label-width="item.labelWidth"
        >
          <template v-if="item.type == 'render'">
            <view-render :item="item" :object="object" :render="item.render" />
          </template>
          <template v-else-if="item.type == 'file'">
            <template v-if="object[item.prop]">
              <template v-if="item.uploadType=='file'">
                <file-type :files="object[item.prop]" />
              </template>
              <template v-for="(img,i) in object[item.prop].split(';')" v-else>
                <el-image
                  :key="i"
                  style="width: 150px; height: 150px"
                  fit="cover"
                  alt="点击查看大图"
                  :src="img|imgPath"
                  :preview-src-list="getSrcList(object.image)"
                />
              </template>
            </template>
          </template>
          <template v-else-if="['year', 'month', 'date', 'week', 'datetime'].indexOf(item.type)!=-1">
            {{ object[item.prop]|dateFormat(item.format) }}
          </template>
          <template v-else-if="item.type == 'editor'">
            <div v-html="object[item.prop]" />
          </template>
          <template v-else-if="item.type == 'area'">
            <template v-for="(i) in item.objKeys" v-if="i.tableShow">
              {{ object[i.field] }}
            </template>
          </template>
          <template v-else>
            <template v-if="item.dataDic">
              {{ setDictData(item.dataDic,object[item.prop]) }}
            </template>
            <template v-else>
              {{ object[item.prop] }}
            </template>
          </template>
        </el-form-item>
      </template>
    </el-form>
  </div>
</template>

<script>
import ViewRender from './viewRender'
import { imgPath } from '../../../filters'
import FileType from '../components/fileType'
export default {
  name: 'WiseView',
  components: { FileType, ViewRender },
  props: {
    columns: {
      type: Array,
      required: true
    },
    object: {
      type: Object
    }
  },
  methods: {
    getSrcList(str) {
      let arr = []
      if (str) {
        arr = str.split(';')
      }
      return arr.map(item => imgPath(item))
    },
    setDictData(dataDic, value) {
      let label
      const options = require('../data/dataDictionary')[dataDic]
      if (options && options.length > 0) {
        const obj = options.find(item => item.value === value)
        if (obj) {
          label = obj.label
        }
      }
      return label
    }
  }
}
</script>

<style scoped>

</style>
